package com.caszx.chargingpile.holder.station;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.app.base.adapter.holder.BaseHolder;
import com.caszx.chargingpile.R;
import com.caszx.chargingpile.activity.ReservatePayActivity;
import com.caszx.chargingpile.entity.EntityStation;
import com.caszx.chargingpile.user.LocationManager;
import com.caszx.chargingpile.utils.DialogHelp;
import java.text.DecimalFormat;

/**
 * Created by think on 2016/3/7.
 */
public class StationListHolder extends BaseHolder<EntityStation> implements View.OnClickListener{

    private TextView txtTitle;
    private TextView  txtDistance;

    private TextView  txtInfo;

    private TextView  txt_priceAc;
    private TextView  txt_stopcarFee;
    private TextView  txt_serverFeeAc;

    private TextView  btn_reservate;
    private TextView  btn_go;

    private static DecimalFormat decimalFormat = new DecimalFormat("###.##");

    public StationListHolder(View view) {
        super(view);
    }

    @Override
    protected void initView() {
        txtTitle = (TextView) mRootView.findViewById(R.id.txtTitle);
        txtDistance = (TextView) mRootView.findViewById(R.id.txtDistance);
        txtInfo = (TextView) mRootView.findViewById(R.id.txtInfo);
        txt_priceAc = (TextView) mRootView.findViewById(R.id.txt_priceAc);
        txt_stopcarFee = (TextView) mRootView.findViewById(R.id.txt_stopcarFee);
        txt_serverFeeAc = (TextView) mRootView.findViewById(R.id.txt_serverFeeAc);
        btn_reservate = (TextView) mRootView.findViewById(R.id.btn_reservate);
        btn_go = (TextView) mRootView.findViewById(R.id.btn_go);
    }

    @Override
    protected void refreshView() {
        txtTitle.setText(mItem.name);
        txtDistance.setText(decimalFormat.format(mItem.distence/1000)+"Km");
        txtInfo.setText(mItem.fastRuningPile+"个快充 "+mItem.slowRuningPile+"个慢充");
        txt_priceAc.setText("充电费"+decimalFormat.format(mItem.priceDc)+"元/度");
        txt_stopcarFee.setText("停车费"+decimalFormat.format(mItem.stopcarFee)+"元/小时");
        txt_serverFeeAc.setText("服务费"+decimalFormat.format(mItem.stopcarFee)+"元/次");

        btn_reservate.setOnClickListener(this);
        btn_go.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            //预约
            case R.id.btn_reservate:

                Intent intent = new Intent(mRootView.getContext(),ReservatePayActivity.class);
                intent.putExtra("ID",mItem.stationId);
                intent.putExtra("NAME",mItem.name);
                mRootView.getContext().startActivity(intent);

                break;
            //去这里
            case R.id.btn_go:
                double start_longitude = LocationManager.getInstance().getLongitude();
                double start_latitude  =  LocationManager.getInstance().getLatitude();
                String start_title = LocationManager.getInstance().getCityName();
                try {
                    double end_longitude = Double.valueOf(mItem.longitude);
                    double end_latitude  =  Double.valueOf(mItem.latitude);
                    String end_title = mItem.name;
                    LocationManager.getInstance().routeplanToNavi((Activity) mRootView.getContext(),start_longitude,start_latitude,start_title
                            ,end_longitude,end_latitude,end_title );
                }catch (NumberFormatException e){
                    DialogHelp.showDialogOnlyMesg(mRootView.getContext(),"坐标错误!",null);

                }
                break;
        }
    }
}
